import * as TYPES from "../action-types";
import { getBanner,getHotRecommends,getNewAlbums,getTopList,getArtistList } from "services/recommend.js";

let actions = {
    // redux-promise
    getTopBanner:async()=>{
        return {
            type:TYPES.BANNER,
            payload:await getBanner()
            .then( res=>{
                return res.banners
            })
            .catch(err=>console.log(err))

        }
    },
    getHotRecommends:async()=>{
        return {
            type:TYPES.HOT_RECOMMEND,
            payload:await getHotRecommends({limit:8})
            .then( res=>{
                return res.result
            })
            .catch(err=>console.log(err))
        }
    },
    getNewAlbums:async()=>{
        return {
            type:TYPES.NEW_ALBUMS,
            payload:await getNewAlbums({limit:8})
            .then( res=>{
                return res.albums
            })
            .catch(err=>console.log(err))
        }
    },

    getTopList:async ({type,data})=>{ 
        //{type:TYPES.NEW_ALBUMS,data:{idx:0} }
        return {
            type:type,
            payload:await getTopList(data)
            .then( res=>{
                return res.playlist
            })
            .catch(err=>console.log(err))
        }
    },

    getArtistList:async (cat=5001,limit=5)=>{//入驻歌手
        return {
            type:TYPES.ARTIST_LIST,
            payload:await getArtistList({cat,limit})
            .then( res=>{
                return res.artists
            })
            .catch(err=>console.log(err))
        }
    }
    // redux-thunk

    
}

export default actions ;